package wyh.controller.Patient;

import com.fasterxml.jackson.databind.ObjectMapper;
import wyh.pojo.Patient;
import wyh.service.PatientService;
import wyh.vo.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/Patient/update")
public class UpdateServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("访问/Patient/update");

        ObjectMapper ojmapper = new ObjectMapper();
        Patient pojo = ojmapper.readValue(req.getInputStream(), Patient.class);
        PatientService service = new PatientService();
        Boolean a = service.Serviceupdate(pojo);
        wyh.vo.Result result = null;
        if (a) {
            result = new wyh.vo.Result(200, "成功修改", null);
        } else {
            result = new Result(500, "修改失败", null);
        }
        String string = ojmapper.writeValueAsString(result);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(string);
    }
}
